<?php
namespace app\index\service;


use app\index\model\SealModel;
use app\index\model\TaskModel;
use app\index\model\UserModel;
use app\index\model\WuCaiModel;
use app\index\model\WuChuModel;
use app\index\model\WuLingModel;
use app\index\model\WuRuModel;

class XingService extends CommonService
{

    public function get_notice_tongtype(){
        return [
            1=>'通知',
            2=>'公告',
            3=>'决定',
            4=>'通报',
            5=>'其他',
        ];
    }

    public function get_notice_tongtype_show($tongtype=''){
        $arr = $this->get_notice_tongtype();
        return isset($arr[$tongtype]) ? $arr[$tongtype] : '';
    }

    public function get_notice_jietype(){
        return [
            'all' =>'全部',
            'role' =>'角色',
            'dept' =>'部门',
            'gang' =>'岗位',
            'user' =>'用户',
        ];
    }

    public function get_notice_jietype_show($jietype=''){
        $arr = $this->get_notice_jietype();
        return isset($arr[$jietype]) ? $arr[$jietype] : '';
    }


    public function get_notice_jieer_by_jietype($jietype, $jieer){
        $uidArr = [];
        if($jietype == 'all'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->column('id');
        }
        if($jietype == 'role'){
            $where = '';
            foreach (explode(',', $jieer) as $v){
                if(empty($where)){
                    $where = "find_in_set(".$v.",`roleid`)";
                }else{
                    $where .= "or find_in_set(".$v.",`roleid`)";
                }
            }
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->where($where)->column('id');
        }
        if($jietype == 'dept'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('deptid','in',$jieer)->column('id');
        }
        if($jietype == 'gang'){
            $where = '';
            foreach (explode(',', $jieer) as $v){
                if(empty($where)){
                    $where = "find_in_set(".$v.",`gangid`)";
                }else{
                    $where .= "or find_in_set(".$v.",`gangid`)";
                }
            }
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->where($where)->column('id');
        }
        if($jietype == 'user'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('id','in',$jieer)->column('id');
        }

        return implode(',', $uidArr);
    }


    public function get_notice_status_show($status=''){
        $arr = [
            0 => '草稿',
            1 => '已发布',
            2 => '作废',
        ];
        return isset($arr[$status]) ? $arr[$status] : '';
    }






    public function create_wu_cai_number(){
        $tou = 'WPCG';
        $daystr = substr(date("Ymd"), 2);
        $number = WuCaiModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function create_wu_ru_number(){
        $tou = 'WPRK';
        $daystr = substr(date("Ymd"), 2);
        $number = WuRuModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }


    public function create_wu_chu_number(){
        $tou = 'WPCK';
        $daystr = substr(date("Ymd"), 2);
        $number = WuChuModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }


    public function create_wu_ling_number(){
        $tou = 'WPLY';
        $daystr = substr(date("Ymd"), 2);
        $number = WuLingModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }

    public function get_wen_fentype(){
        return [
            1=>'发文分发',
            2=>'收文分发',
        ];
    }

    public function get_wen_fentype_show($fentype=''){
        $arr = $this->get_wen_fentype();
        return isset($arr[$fentype]) ? $arr[$fentype] : '';
    }

    public function get_wenfen_fenuser_by_fendui($fendui, $fener){
        $uidArr = [];
        if($fendui == 'dept'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('deptid','in',$fener)->column('id');
        }
        if($fendui == 'user'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('id','in',$fener)->column('id');
        }

        return implode(',', $uidArr);
    }


    public function check_seal_name($name, $id=0){
        return !!SealModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'deleted_user'=>0])->where('id','neq', $id)->find();
    }


    public function get_asset_state(){
        return [
            1=>'闲置',
            2=>'在用',
            3=>'维修',
            4=>'报废',
        ];
    }

    public function get_asset_state_show($state=''){
        $arr = $this->get_asset_state();
        return isset($arr[$state]) ? $arr[$state] : '';
    }





    public function create_task_number(){
        $tou = 'RW';
        $daystr = substr(date("Ymd"), 2);
        $number = TaskModel::where('number','like','%'.$tou.$daystr.'%')->order('number DESC')->value('number');
        if(!$number){
            $str = $tou.$daystr.'00001';
        }else{
            $str = $tou.((int)str_replace($tou,'',$number)+1);
        }
        return $str;
    }
    public function get_task_youxian(){
        return ['普通','重要','紧急'];
    }
    public function get_task_type(){
        return [
            1=>'投标任务',
            2=>'项目任务',
            3=>'专项任务',
        ];
    }
    public function get_task_type_show($type=''){
        $arr = $this->get_task_type();
        return isset($arr[$type]) ? $arr[$type] : '';
    }

    public function get_task_status(){
        return [
            1=>'待执行',
            3=>'进行中',
            5=>'已完成',
            7=>'已关闭',
        ];
    }
    public function get_task_status_list($status=''){
        $str = '';
        if($status == 1){
            $str = '<span class="mindianhuang"></span>待执行';
        }
        if($status == 3){
            $str = '<span class="mindianlan"></span>进行中';
        }
        if($status == 5){
            $str = '<span class="mindianlv"></span>已完成';
        }
        if($status == 7){
            $str = '<span class="mindianhui"></span>已关闭';
        }
        return $str;
    }
    public function get_task_status_show($status=''){
        $arr = $this->get_task_status();
        return isset($arr[$status]) ? $arr[$status] : '';
    }



    public function get_meet_status($startdt, $enddt){
        $str = '';
        $curdt = date("Y-m-d H:i:s");
        if($curdt < $startdt){
            $str = '未开始';
        }else{
            if($curdt < $enddt){
                $str = '进行中';
            }else{
                $str = '已结束';
            }
        }
        return $str;
    }



}
